from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.sms.v20210111 import sms_client, models
import random
import json


def generate_code():
    code = str(random.randint(10000, 99999))
    return code

cred = credential.Credential("AKIDa1GI9p3OYWGoAJG0Zw75qRq46wZ1HLDr", "WqwoUxDH8oJZbYMyMbeU7XlneIjz2ua5")
# 实例化一个http选项，可选的，没有特殊需求可以跳过
httpProfile = HttpProfile()
httpProfile.endpoint = "sms.tencentcloudapi.com"

# 实例化一个client选项，可选的，没有特殊需求可以跳过
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
# 实例化要请求产品的client对象,clientProfile是可选的
client = sms_client.SmsClient(cred, "ap-guangzhou", clientProfile)

# 实例化一个请求对象,每个接口都会对应一个request对象
req = models.SendSmsRequest()
params = {
    "PhoneNumberSet": ["15279377224"],
    "SmsSdkAppId": "1400855213",
    "SignName": "大四实训公众号",
    "TemplateId": "1932231",
    "TemplateParamSet": [generate_code()]
}
req.from_json_string(json.dumps(params))
resp = client.SendSms(req)
print(resp)
